import 'package:chop/Model/address_entity.dart';
import 'package:chop/common/StringUtils.dart';
import 'package:chop/view/map/New_location.dart';
import 'package:chop/widgets/TextSizeWidget.dart';
import 'package:chop/widgets/TextwidgetNewaddress.dart';
import 'package:chop/widgets/ToastWidget.dart';
import 'package:chop/widgets/appBar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';


class Buy_address extends StatefulWidget {
  @override
  _Buy_addressState createState() => _Buy_addressState();
}

class _Buy_addressState extends State<Buy_address> {
  TextEditingController _address; //地址
  TextEditingController _Specific_floor_number; //具体门牌号
  TextEditingController _telephone_number; //发货人电话
  TextEditingController _Specific_name; //发货人姓名
  AdrEntityData data;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _address = TextEditingController();
    _Specific_floor_number = TextEditingController();
    _telephone_number = TextEditingController();
    _Specific_name = TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BaseViewBar(
          childView: BaseTitleBar("请选择购买地址"),
          preferredSize: Size.fromHeight(50.0),
        ),
        body: Stack(
          children: <Widget>[
            ListView(
              children: <Widget>[
                Container(
                  padding: EdgeInsets.fromLTRB(20.0, 30.0, 10.0, 20.0),
                  child: Form(
//          key: _formKey,//绑定状态属性
                    child: Column(
                      children: <Widget>[
                        TextWidgetNew(
                          controller: _address,
                          helperText: "请在地图上选取送达地址",
                          labelText: "address",
                          click: () async {
                            data = await Get.to(NewLocation());
                            if(data != null){
                              print(data.address);
                              data.address = getAddress(data.address);
                              print(data.address);
                              _address.text = data.address;
                              print("____________<${data.address}");
                            }
                          },
                        )
                      ],
                    ),
                  ),
                ),
              ],
            ),
            Positioned(
              bottom: 0,
              width: MediaQuery.of(context).size.width,
              child: Container(
                child: Row(
                  children: <Widget>[
                    Expanded(
//                      flex: 7,
                      child: RaisedButton(
                        //提交按钮
                        color: Colors.lightBlueAccent,
                        highlightColor: Colors.blueAccent,
                        splashColor: Colors.blue,
                        colorBrightness: Brightness.dark,
//                        shape: RoundedRectangleBorder(
//                          //四角圆角
//                            borderRadius: BorderRadius.circular(10)),
                        onPressed: () async {
                          if (StringUtils.isNull(_address.text)) {
                            return Toast.toast(context,
                                msg: "请选择购买地址",
                                position: ToastPostion.bottom);
                          } else {
                            print(_Specific_name.text.trim());
                            Get.back(result: data);
                          }
                        },
                        child: FixedSizeText(
                          '提交地址',
                          style: TextStyle(color: Colors.white, fontSize: 15),
                        ),
                      ),
                    ),

                  ],
                ),

              ),
            ),
          ],
        ));
  }
  
  
  String getAddress(String str){
    List<String> arr = str.split(",");
    return "${arr[0]} ${arr[1]}";
  }
}
